﻿
/// <reference path="/js/framework/jquery-1.4.1-vsdoc.js" />
/// <reference path="/js/framework/jquery-1.4.1.min.js" />
/// <reference path="/js/framework/jquery-jtemplates.js" />
/// <reference path="/framework/jquery.ui.core.js" />
/// <reference path="/framework/jquery.ui.mouse.js" />
/// <reference path="/framework/jquery.ui.widget.js" />
/// <reference path="/framework/jquery.ui.draggable.js" />
/// <reference path="/js/plugin/alert/js/jquery.alerts.js" />
/// <reference path="/jquery.flot.min.js" />
/// <reference path="/js/socialshop-common.js" />
/// <reference path="/js/Message.js" />
/// <reference path="/js/popup/Loading.js" />
/// <reference path="/CONSTANT.js" />
/// <reference path="/vtc.paging.small.js" />
/// <reference path="../../socialshop-utils.js" />

//----------------------------------------------
// Description: Các Script dùng chung mua hàng theo nhóm
//----------------------------------------------

BUYINGGROUP = new function () {

    this.processFlotPeople = function (value) {
        var arr = new Array();
        arr = value.split(',');
        var people = new Array();
        for (i = 0; i < arr.length; i++) {
            people[i] = parseInt(arr[i].split('-')[0]);
        }
        return people;
    };

    this.processFlotPrice = function (value) {
        var arr = new Array();
        arr = value.split(',');
        var price = new Array();
        for (i = 0; i < arr.length; i++) {
            price[i] = parseInt(arr[i].split('-')[1]);

        }
        return price;
    };

    this.processPointPrice = function (value) {
        var arr = new Array();
        arr = value.split(',');
        var price = new Array();
        var people = new Array();
        var pricePoint = new Array();
        for (i = 0; i < arr.length; i++) {
            price[i] = parseInt(arr[i].split('-')[1]);
            people[i] = parseInt(arr[i].split('-')[0]);
            pricePoint[i] = Array(people[i], price[i]);
        }
        return pricePoint;
    };

    this.MinPeople = function (value) {
        var arr = new Array();
        arr = value.split(',');
        var People;
        var _temp = parseInt(arr[0].split('-')[0]);
        for (i = 0; i < arr.length; i++) {
            People = parseInt(arr[i].split('-')[0]);
            if (_temp > People) _temp = People;
        }
        return _temp;
    };

    this.MaxPeople = function (value) {
        var arr = new Array();
        arr = value.split(',');
        var People;
        var _temp = parseInt(arr[0].split('-')[0]);
        for (i = 0; i < arr.length; i++) {
            People = parseInt(arr[i].split('-')[0]);
            if (_temp < People) _temp = People;
        }
        return _temp;
    };

    this.MinPricePoint = function (value) {
        var arr = new Array();
        arr = value.split(',');
        var _temp = parseInt(arr[0].split('-')[1]);
        for (i = 0; i < arr.length; i++) {
            if (_temp > parseInt(arr[i].split('-')[1])) _temp = parseInt(arr[i].split('-')[1]);
        }
        return _temp;
    };

    this.MaxPricePoint = function (value) {
        var arr = new Array();
        arr = value.split(',');
        var _temp = parseInt(arr[0].split('-')[1]);
        for (i = 0; i < arr.length; i++) {
            MinPrice = arr[0];
            if (_temp < parseInt(arr[i].split('-')[1])) _temp = parseInt(arr[i].split('-')[1]);
        }
        return _temp;
    };

    this.compareDateTime = function (strDate1, strDate2) {
        var date1 = new Date(strDate1);
        var date2 = new Date(strDate2);
        if (date1 >= date2) {
            return true;
        }
        else return false;
    };

    this.CaculatorTime = function (totalSeconds) {
        if (totalSeconds <= 0)
            return "00 : 00 : 00";
        hour = parseInt(totalSeconds / 3600);
        minute = parseInt((totalSeconds - hour * 3600) / 60);
        second = totalSeconds - hour * 3600 - minute * 60;
        if (hour < 10)
            _hour = "0" + hour.toString();
        else _hour = hour.toString();
        if (minute < 10)
            _minute = "0" + minute.toString();
        else _minute = minute.toString();
        if (second < 10)
            _second = "0" + second.toString();
        else _second = second.toString();
        return _hour + " : " + _minute + " : " + _second;
    };

    this.showTooltips = function (x, y, contents) {
        $('<div id="tooltip">' + contents + '</div>').css({
            position: 'absolute',
            display: 'block',
            top: y - 35,
            'z-index': 1000,
            left: x - 3,
            border: '1px solid #fdd',
            padding: '2px',
            'background-color': '#fee'
        }).appendTo("body").fadeIn(200);
    };

    this.DateCompare = function (date1Str, date2Str) {
        var dtCh = "/";
        var dtSc = ":";

        var pos1 = date1Str.indexOf(dtCh);
        var pos2 = date1Str.indexOf(dtCh, pos1 + 1);
        var pos3 = date1Str.indexOf(dtSc);
        var pos4 = date1Str.indexOf(dtSc, pos3 + 1);

        var strDay = date1Str.substring(0, pos1);
        var strMonth = date1Str.substring(pos1 + 1, pos2);
        var strYear = date1Str.substring(pos2 + 1);

        var strHour = date1Str.substring(0, pos3);
        var strMinute = date1Str.substring(pos3 + 1, pos4);
        var strSecond = date1Str.substring(pos4 + 1);

        var date1 = new Date(strYear, strMonth, strDay, strHour, strMinute, strSecond);
        pos1 = date2Str.indexOf(dtCh);
        pos2 = date2Str.indexOf(dtCh, pos1 + 1);
        pos3 = date2Str.indexOf(dtSc);
        pos4 = date2Str.indexOf(dtSc, pos3 + 1);
        strDay = date2Str.substring(0, pos1);
        strMonth = date2Str.substring(pos1 + 1, pos2);
        strYear = date2Str.substring(pos2 + 1);

        strHour = date2Str.substring(0, pos3);
        strMinute = date2Str.substring(pos3 + 1, pos4);
        strSecond = date2Str.substring(pos4 + 1);

        var date2 = new Date(strYear, strMonth, strDay, strHour, strMinute, strSecond);
        if (date1 >= date2) {
            return false;
        }
        else {
            return true;
        }
    };

    this.CaculatorTime1 = function (totalSeconds) {
        var _second1 = '0';
        var _second2 = '0';
        var _minute1 = '0';
        var _minute2 = '0';
        var _hour1 = '0';
        var _hour2 = '0';
        var _hour3 = '0';
        var _html = '';
        if (totalSeconds > 0) {
            hour = parseInt(totalSeconds / 3600);
            minute = parseInt((totalSeconds - hour * 3600) / 60);
            second = totalSeconds - hour * 3600 - minute * 60;

            if (hour > 99) {
                _hour3 = Math.floor(hour / 100);
                _hour2 = Math.floor((hour % 100) / 10);
                _hour1 = hour % 10;
            }
            else if (hour > 9) {
                _hour3 = 0;
                _hour2 = Math.floor(hour / 10);
                _hour1 = hour % 10;
            }
            else {
                _hour3 = 0;
                _hour2 = 0;
                _hour1 = hour;
            }

            if (minute > 9) {
                _minute2 = Math.floor(minute / 10);
                _minute1 = minute % 10;
            }
            else {
                _minute2 = 0;
                _minute1 = minute;
            }

            if (second > 9) {
                _second2 = Math.floor(second / 10);
                _second1 = second % 10;
            }
            else {
                _second2 = 0;
                _second1 = second;
            }
        }
        _html = '<ul id="ulTime">' +
                        '<li id="liHour3" class="num_time png">' + _hour3 + '</li>' +
                        '<li id="liHour2" class="num_time png">' + _hour2 + '</li>' +
                        '<li id="liHour1" class="num_time png">' + _hour3 + '</li>' +
                        '<li class="dot">:</li>' +
                        '<li id="liMinute2" class="num_time png">' + _minute2 + '</li>' +
                        '<li id="liMinute1" class="num_time png">' + _minute1 + '</li>' +
                        '<li class="dot">:</li>' +
                        '<li id="liSecond2" class="num_time png">' + _second2 + '</li>' +
                        '<li id="liSecond1" class="num_time png">' + _second1 + '</li>' +
                    '</ul>';
        return _html;
    };
}